//
//  ViewController.m
//  UI05_Rainbow Lamp
//
//  Created by dllo on 16/6/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "RainbowView.h"
#import "RainbowLamp.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creatRainbowLamp];
//    [self creatSelfRainbow];
}


-(void)creatRainbowLamp{
    
    NSMutableArray *colorArray = [NSMutableArray arrayWithObjects:[UIColor redColor],[UIColor yellowColor], [UIColor blueColor], [UIColor greenColor], [UIColor orangeColor], [UIColor purpleColor], [UIColor grayColor], nil];
    for (int i = 0; i < 7 ; i ++) {
        RainbowView *view = [[RainbowView alloc]initWithFrame:CGRectMake(0 + i * 20, 0 + i * 20, self.view.frame.size.width - 40 * i, self.view.frame.size.height - i * 40)];
        view.tag = 100 + i;
        view.backgroundColor = colorArray[i];
        [self.view addSubview:view];
        [view release];
    }
    [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(time) userInfo:nil repeats:YES];
    
}
-(void)time{
    UIColor *temp = [self.view viewWithTag:100].backgroundColor;
    for (int i = 0; i < 7; i ++) {
        [self.view viewWithTag:100 + i].backgroundColor = [self.view viewWithTag:101 + i].backgroundColor;
    }
    [self.view viewWithTag:106].backgroundColor = temp;
}




-(void)creatSelfRainbow{
    RainbowLamp *selfRainbow = [[RainbowLamp alloc]initWithFrame:CGRectMake(100, 100, 100, 100) withColorCounts:6];
    [self.view addSubview:selfRainbow];
    [selfRainbow release];
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
